<?php

/**
 * This is the model class for table "lths_lend".
 *
 * The followings are the available columns in table 'lths_lend':
 * @property integer $id
 * @property string $lend_date
 * @property integer $out_method
 * @property string $lend_staff
 * @property integer $producttype_code
 * @property string $product_id
 * @property string $imei
 * @property integer $lend_number
 * @property string $receive_staff
 * @property string $remark
 * @property string $update_staff
 * @property string $create_time
 * @property string $update_time
 *
 * The followings are the available model relations:
 * @property Product $product
 * @property User $lendStaff
 * @property BOutmethod $outMethod
 * @property Producttype $producttypeCode
 */
class Lend extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Lend the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'lths_lend';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('lend_date, out_method, producttype_code, lend_number', 'required'),
			array('out_method, producttype_code, lend_number', 'numerical', 'integerOnly'=>true),
			array('lend_staff, receive_staff', 'length', 'max'=>20),
			array('product_id', 'length', 'max'=>15),
			array('imei', 'length', 'max'=>50),
			array('remark', 'length', 'max'=>500),
			array('create_time, update_time, update_staff', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, lend_date, out_method, lend_staff, producttype_code, product_id, imei, lend_number, receive_staff, remark, create_time, update_time', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'product' => array(self::BELONGS_TO, 'Product', 'product_id'),
			'lendStaff' => array(self::BELONGS_TO, 'User', 'lend_staff'),
			'outMethod' => array(self::BELONGS_TO, 'BOutmethod', 'out_method'),
			'producttypeCode' => array(self::BELONGS_TO, 'Producttype', 'producttype_code'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'lend_date' => '日期',
			'out_method' => '出库方式',
			'lend_staff' => '出借人',
			'producttype_code' => '产品类型',
			'product_id' => '规格型号',
			'imei' => '串码',
			'lend_number' => '数量',
			'receive_staff' => '接收人',
			'remark' => '备注',
			'create_time' => 'Create Time',
			'update_time' => 'Update Time',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('lend_date',$this->lend_date,true);
		$criteria->compare('out_method',$this->out_method);
		$criteria->compare('lend_staff',$this->lend_staff,true);
		$criteria->compare('producttype_code',$this->producttype_code);
		$criteria->compare('product_id',$this->product_id,true);
		$criteria->compare('imei',$this->imei,true);
		$criteria->compare('lend_number',$this->lend_number);
		$criteria->compare('receive_staff',$this->receive_staff,true);
		$criteria->compare('remark',$this->remark,true);
		$criteria->compare('create_time',$this->create_time,true);
		$criteria->compare('update_time',$this->update_time,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	
	public function behaviors(){  
    return array(  
        'CTimestampBehavior' => array(  
            'class' => 'zii.behaviors.CTimestampBehavior',  
            'createAttribute' => 'create_time',  
            'updateAttribute' => 'update_time',  
        )  
      );  
    }  
}